package com.yln.watcher;

import com.yln.watcher.client.ZkClient;
import lombok.RequiredArgsConstructor;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;

@RequiredArgsConstructor
public class MasterElectionWatcher implements Watcher {

    private final ZkClient client;

    @Override
    public void process(WatchedEvent event) {
        Event.EventType eventType = event.getType();
        switch (eventType) {
            case NodeDeleted:
                client.tryBecomeMaster();
                break;
            default:
                break;
        }
    }
}
